package com.cn.demo.controller;

import com.cn.demo.entity.LeakyBucket;
import com.cn.demo.service.LeakyBucketService;
import com.cn.demo.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 漏桶算法接口
 *
 * @author wangjf
 * @version 1.0
 * @createDate 2019/11/19 10:26
 * @projectName demo
 */
@RestController
@RequestMapping("/leaky/bucket")
public class LeakyBucketController {

    @Autowired
    private LeakyBucketService leakyBucketService;

    /**
     * 功能描述: 使用漏桶算法进行秒杀
     * @author: wangjf
     * @createTime: 2019/12/6 14:06
     * @param leakyBucket
     * @return com.cn.demo.util.R<java.lang.String>
     */
    @PostMapping
    public R<String> seckill(@RequestBody LeakyBucket leakyBucket) {
        leakyBucketService.sendMq(leakyBucket);
        return R.ok();
    }

    /**
     * 功能描述: 使用线程池发送至mq
     * @author: wangjf
     * @createTime: 2019/12/6 14:57
     * @param leakyBucket
     * @return com.cn.demo.util.R<java.lang.String>
     */
    @PostMapping("/pool")
    public R<String> poolSeckill(@RequestBody LeakyBucket leakyBucket) {
        leakyBucketService.poolSendMq(leakyBucket);
        return R.ok();
    }



}
